package com.luguokong.pet_rescue.mapper;

import com.luguokong.pet_rescue.pojo.Essay;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface EssayMapper {
    public int insertEssay(Essay essay);
    public int deleteEssayById(int essayId);
    public int updateEssayById(Essay essay);
    public Essay selectEssayById(int essayId);
    public List<Essay> selectPubEssayAllByUserId(int user_id);
    public List<Essay> selectUnPubEssayAllByUserId(int user_id);
    public List<Essay> selectEssayAll();

    @Select("select * from essays limit #{pageNum},#{pageSize}")
    public List<Essay> selectEssayAllByPageNumByPageSize(int pageNum, int pageSize);

    @Select("select count(*) from essays")
    public int selectDataCount();

    public int deleteEssayByEssayIdArray(int [] essayIdArr);

//    查询近六个月按月分组的数据
    @Select("select date_format(pub_date, '%m') as months, count(essay_id) as 'count' from essays " +
            "where is_delete = 0 and date_sub(curdate(), interval 6 month) <= date(pub_date) " +
            "group by months")
    public List<Map<String, Number>> selectCountByRecentSixMGroupByMonth();
}
